/**
 * 
 */
package com.pengtu.service.detect;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.dao.QueryFilter;
import com.pengtu.dao.detect.grade.BranchDao;
import com.pengtu.dao.detect.grade.ProjquacheckDao;
import com.pengtu.dao.detect.grade.SignProjQuaCheckDao;
import com.pengtu.dao.detect.grade.SubentryCheckDao;
import com.pengtu.dao.detect.grade.UnitProjDao;
import com.pengtu.entity.detect.grade.Branch;
import com.pengtu.entity.detect.grade.Projquacheck;
import com.pengtu.entity.detect.grade.SignProjQuaCheck;
import com.pengtu.entity.detect.grade.Subentry;
import com.pengtu.entity.detect.grade.UnitProj;

/**
 * @author Administrator
 * 
 */
@Component
@Transactional
public class ProjquacheckManager {

	private ProjquacheckDao projquacheckDao;
	private BranchDao branchDao;
	private SignProjQuaCheckDao signProjQuaCheckDao;
	private SubentryCheckDao subentryCheckDao;
	private UnitProjDao unitProjDao;

	// ******************【 工程质量基础表 】***********************//
	public void saveProjquacheck(Projquacheck projquacheck) {
		projquacheckDao.save(projquacheck);
	}

	@Transactional(readOnly = true)
	public List<Projquacheck> findAllProjquacheck() {
		return projquacheckDao.getAll("branchProjCode", true);
	}

	@Transactional(readOnly = true)
	public Projquacheck findByProperty(String propery, String value) {
		// TODO Auto-generated method stub
		if ("id".equals(propery))
			return projquacheckDao.get(value);
		return projquacheckDao.findUniqueBy(propery, value);
	}

	// ******************【 工程分部鉴定表 】***********************//
	public void saveProjBranch(Branch branch) {
		branchDao.save(branch);
	}

	@Transactional(readOnly = true)
	public Branch findByProjBranch(String propertyName, String value) {
		if ("id".equalsIgnoreCase(propertyName))
			return branchDao.get(value);
		return branchDao.findUniqueBy(propertyName, value);
	}

	@Transactional(readOnly = true)
	public List<Branch> findProjBranchList(String propertyName, String value) {
		return branchDao.findBy(propertyName, value);
	}

	// ******************【 工程合同段鉴定表 】***********************//
	public void saveProjSign(SignProjQuaCheck signProjQuaCheck) {
		signProjQuaCheckDao.save(signProjQuaCheck);
	}

	@Transactional(readOnly = true)
	public SignProjQuaCheck findByProjSign(String propertyName, String value) {
		if ("id".equalsIgnoreCase(propertyName))
			return signProjQuaCheckDao.get(value);
		return signProjQuaCheckDao.findUniqueBy(propertyName, value);
	}
	
	@Transactional(readOnly = true)
	public SignProjQuaCheck findByQuerySign(QueryFilter queryFilter) {
		if(signProjQuaCheckDao.find(queryFilter).size()>0){
			return signProjQuaCheckDao.find(queryFilter).get(0);
		}
		return null;
	}

	@Transactional(readOnly = true)
	public List<SignProjQuaCheck> findProjSignList(String propertyName,
			String value) {
		return signProjQuaCheckDao.findBy(propertyName, value);
	}
	
	public void deleteSignproj(String id) {
		// TODO Auto-generated method stub
		signProjQuaCheckDao.delete(id);
	}

	// ******************【 工程分项鉴定表 】***********************//
	public void saveSubentry(Subentry subentry) {
		subentryCheckDao.save(subentry);
	}
	
	public void deleteSub(Subentry sub) {
		// TODO Auto-generated method stub
		subentryCheckDao.delete(sub);
	}

	@Transactional(readOnly = true)
	public Subentry findBySubentry(String propertyName, String value) {
		if ("id".equalsIgnoreCase(propertyName))
			return subentryCheckDao.get(value);
		return subentryCheckDao.findUniqueBy(propertyName, value);
	}
	
	@Transactional(readOnly = true)
	public List<Subentry> searchSubList(String signcheckId) {
		// TODO Auto-generated method stub
		
		return subentryCheckDao.findBySigncheck(signcheckId);
	}

	@Transactional(readOnly = true)
	public List<Subentry> findByHqlSignProj(String value) {
//		String hql="select sub from Subentry sub where sub.branch.unitProj.signQuaCheck.projId = '"+value+"' order by  sub.branch.unitProj.signQuaCheck.id , sub.subentryCode ";
		return subentryCheckDao.findBySignProj(value);
	}
	
	@Transactional(readOnly = true)
	public List<Subentry> findByHqlSigncheck(String value) {
//		String hql="select sub from Subentry sub where sub.branch.unitProj.signQuaCheck.projId = '"+value+"' order by  sub.branch.unitProj.signQuaCheck.id , sub.subentryCode ";
		return subentryCheckDao.findBySigncheck(value);
	}
	
	@Transactional(readOnly = true)
	public List<Subentry> findSubentryList(String propertyName, String value) {
		return subentryCheckDao.findBy(propertyName, value);
	}

	// ******************【 工程单位工程鉴定表 】***********************//
	public void saveUnitProj(UnitProj unitProj) {
		unitProjDao.save(unitProj);
	}

	@Transactional(readOnly = true)
	public UnitProj findByUnitProj(String propertyName, String value) {
		if ("id".equalsIgnoreCase(propertyName))
			return unitProjDao.get(value);
		return unitProjDao.findUniqueBy(propertyName, value);
	}

	@Transactional(readOnly = true)
	public List<UnitProj> findUnitProjList(String propertyName, String value) {
		return unitProjDao.findBy(propertyName, value);
	}

	@Autowired
	public void setProjquacheckDao(ProjquacheckDao projquacheckDao) {
		this.projquacheckDao = projquacheckDao;
	}

	@Autowired
	public void setBranchDao(BranchDao branchDao) {
		this.branchDao = branchDao;
	}

	@Autowired
	public void setSignProjQuaCheckDao(SignProjQuaCheckDao signProjQuaCheckDao) {
		this.signProjQuaCheckDao = signProjQuaCheckDao;
	}

	@Autowired
	public void setsubentryCheckDao(SubentryCheckDao subentryCheckDao) {
		this.subentryCheckDao = subentryCheckDao;
	}

	@Autowired
	public void setUnitProjDao(UnitProjDao unitProjDao) {
		this.unitProjDao = unitProjDao;
	}


}
